let root = [1]
function TreeNode(val, left, right) {
    this.val = (val === undefined ? 0 : val);
    this.left = (left === undefined ? null : left);
    this.right = (right === undefined ? null : right);
}

// 将数组转换为二叉树
function arrayToTree(arr) {
    if (arr.length === 0 || arr[0] === null) return null;

    const root = new TreeNode(arr[0]);
    const queue = [root];
    let i = 1;

    while (queue.length > 0 && i < arr.length) {
        const current = queue.shift();

        // 处理左子节点
        if (i < arr.length && arr[i] !== null) {
            current.left = new TreeNode(arr[i]);
            queue.push(current.left);
        }
        i++;

        // 处理右子节点
        if (i < arr.length && arr[i] !== null) {
            current.right = new TreeNode(arr[i]);
            queue.push(current.right);
        }
        i++;
    }

    return root;
}

var levelOrder = function (root) {
    if (root === null) return []
    const res = []
    const queue = [root]
    while (queue.length > 0) {
        const arr = []
        const levelength = queue.length
        for (let i = 0; i < levelength; i++) {
            const current = queue.shift()
            arr.push(current.val)
            if (current.left) {
                queue.push(current.left)
            }
            if (current.right) {
                queue.push(current.right)
            }
        }
        res.push(arr)
    }
    return res
};

// 转换数组为二叉树
const treeRoot = arrayToTree(root);
// 执行中序遍历并打印结果
console.log(levelOrder(treeRoot)); // 输出: [1, 3, 2]